package com.tms.order.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.tms.order.domain.Exception;
import com.tms.order.service.IExceptionService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 异常统计Controller
 *
 * @author ruoyi
 * @date 2024-10-29
 */
@RestController
@RequestMapping("/exception")
public class ExceptionController extends BaseController
{
    @Autowired
    private IExceptionService exceptionService;

    /**
     * 查询异常统计列表
     */
    @RequiresPermissions("exception:exception:list")
    @GetMapping("/list")
    public TableDataInfo list(Exception exception)
    {
        startPage();
        List<Exception> list = exceptionService.selectExceptionList(exception);
        return getDataTable(list);
    }

    /**
     * 导出异常统计列表
     */
    @RequiresPermissions("exception:exception:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, Exception exception)
    {
        List<Exception> list = exceptionService.selectExceptionList(exception);
        ExcelUtil<Exception> util = new ExcelUtil<Exception>(Exception.class);
        util.exportExcel(response, list, "异常统计数据");
    }

    /**
     * 获取异常统计详细信息
     */
    @RequiresPermissions("exception:exception:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(exceptionService.selectExceptionById(id));
    }

    /**
     * 新增异常统计
     */
    @RequiresPermissions("exception:exception:add")
    @PostMapping
    public AjaxResult add(@RequestBody Exception exception)
    {
        return toAjax(exceptionService.insertException(exception));
    }

    /**
     * 修改异常统计
     */
    @RequiresPermissions("exception:exception:edit")
    @PutMapping
    public AjaxResult edit(@RequestBody Exception exception)
    {
        return toAjax(exceptionService.updateException(exception));
    }

    /**
     * 删除异常统计
     */
    @RequiresPermissions("exception:exception:remove")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(exceptionService.deleteExceptionByIds(ids));
    }

    //异常订单统计
    @PostMapping("countException")
    public TableDataInfo countException(Exception exception)
    {
//        System.out.println(exception);
        startPage();
        List<Exception> list = exceptionService.countException(exception);
        return getDataTable(list);
    }
}
